<%@page contentType="text/html;charset=utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<html>
	<head>
		<title>生成订单 - 当当网</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="../css/login.css" rel="stylesheet" type="text/css" />
		<link href="../css/page_bottom.css" rel="stylesheet" type="text/css" />
		<link href="../css/book.css" rel="stylesheet" type="text/css" />
		<link href="../css/second.css" rel="stylesheet" type="text/css" />
		<link href="../css/secBook_Show.css" rel="stylesheet" type="text/css" />
		<link href="../css/list.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../js/prototype-1.6.0.3.js"></script>
		<link rel="stylesheet" href="../css/gwap.css" type="text/css" />
	</head>
	<body>
		<div style="width: 962px; margin: auto;">
		<%@include file="../common/head3.jsp"%>
		<a href="../main/index.action"><img
					src="../images/default/book_banner_081203.jpg" border="0" /> </a>
		</div>
		<div class="login_step">
			生成订单骤: 1.确认订单 》
			<span class="red_bold"> 2.填写送货地址</span> 》 3.订单成功
		</div>
		<div class="fill_message">
			<p>
				选择地址：
				<select id="address" onchange="fillForm(this.selectedIndex)">
					<option>
						--填写新地址--
					</option>
				</select>
			</p>
			<form name="ctl00" method="post" action="createorder.action" id="add" onsubmit="checkcart();">
				<input type="hidden" name="address.id" id="addressId" />
				<table class="tab_login">
					<tr>
						<td valign="top" class="w1">
							收件人姓名：
						</td>
						<td>
							<input type="text" class="text_input" name="address.receiveName"
								id="receiveName" onblur="checkinput();" />
							<div class="text_left" id="nameValidMsg">
								<span id="receiveNameinfo" ></span>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							收件人详细地址：
						</td>
						<td>
							<input type="text" name="address.fullAddress" class="text_input"
								id="fullAddress" />
							<div class="text_left" id="addressValidMsg">
								<p>
									请填写有效的收件人的详细地址
								</p>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							邮政编码
						</td>
						<td>
							<input type="text" class="text_input" name="address.postalCode"
								id="postalCode" />
							<div class="text_left" id="codeValidMsg">
								<p>
									请填写有效的收件人的邮政编码
								</p>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							电话
						</td>
						<td>
							<input type="text" class="text_input" name="address.phone"
								id="phone" />
							<div class="text_left" id="phoneValidMsg">
								<p>
									请填写有效的收件人的电话
								</p>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							手机
						</td>
						<td>
							<input type="text" class="text_input" name="address.mobile"
								id="mobile" />
							<div class="text_left" id="mobileValidMsg">
								<p>
									请填写有效的收件人的手机
								</p>
							</div>
						</td>
					</tr>
				</table>

				<div class="login_in">
					<input id="btnClientRegister" class="button_1" name="submit"
						type="button" value="取消" />
					<input id="btnClientRegister" class="button_1" name="submit"
						type="submit" value="下一步" />
				</div>
			</form>
		</div>

		<script text="text/javascript">
	var addressArray = null; // 全局变量
	new Ajax.Request('get_address.action', {
			method : 'get',
			onSuccess : function(req) {
				//将其赋值给addressArray
			addressArray = req.responseText.evalJSON().addressList;
			fillAddress();
		}
	});

	//填满地址选择框
	function fillAddress() {
		var addressList = $("address");
		for ( var i = 0; i < addressArray.length; i++) {
			addressList.options[i + 1] = new Option(
					addressArray[i].fullAddress, addressArray[i].id);
		}
		fillForm(0);
	}

	//填满地址表单
	function fillForm(index) {
		if (index == 0) {
			$("receiveName").value = "";
			$("fullAddress").value = "";
			$("postalCode").value = "";
			$("phone").value = "";
			$("mobile").value = "";
			$("addressId").disabled = true;
		} else { //下标值从0开始
			$("receiveName").value = addressArray[index - 1].receiveName;
			$("fullAddress").value = addressArray[index - 1].fullAddress;
			$("postalCode").value = addressArray[index - 1].postalCode;
			$("phone").value = addressArray[index - 1].phone;
			$("mobile").value = addressArray[index - 1].mobile;
			$("addressId").disabled = false;
			$("addressId").value = addressArray[index - 1].id;
		}
	}
	
	
	//检测输入是否正常
	function checkinput(){
			
		var receiveName = $('receiveName').value;
		if(receiveName.length <=1){
			$('receiveNameinfo').innerHTML = '请填写有效的收件人姓名';   
		} else{
			$('receiveNameinfo').innerHTML = '';   
		}
	}
	
	
	function checkcart(){
		
		
	}
</script>
		<%@include file="../common/foot1.jsp"%>
	</body>
</html>